package com.erp.collect.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.collect.domain.dto.TranslateWords;
import com.erp.collect.mapper.ErpKakaCollectProductExpandMapper;
import com.erp.collect.mapper.ErpKakaCollectProductMapper;
import com.erp.collect.mapper.ErpKakaCollectProductSkuMapper;
import com.erp.collect.service.IErpCollectProductCommonService;
import com.erp.collect.service.IErpKakaCollectProductService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.ImageMergeUtils;
import com.ruoyi.common.core.utils.oldUtils.StringUtils;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.gather.api.RemoteCollectProductService;
import com.ruoyi.gather.api.domain.ErpProductAtlas;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.dto.OssUrlDto;
import com.ruoyi.system.api.domain.vo.SysOssVo;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 采集商品合规性处理过程中的公共方法
 *
 * @author erp
 * @date 2024-05-16
 */
@RequiredArgsConstructor
@Service
public class ErpCollectProductCommonServiceImpl implements IErpCollectProductCommonService {

    private final RestTemplate restTemplate;

    /**
     * @Description: 文本翻译
     * @Author: j.zh
     * @Date: 2024/5/17
     * @param words
     * @return
     * @Version: 4.0.0
    **/
    @Override
    public String translate(String words) {
        TranslateWords translateWords = new TranslateWords();
        translateWords.setContent(words);
        System.out.println("translateWords:"+words);
        ResponseEntity<String> forEntity = restTemplate.postForEntity(
                "http://47.94.131.193:8000/cntranslateen", translateWords, String.class);
        String body = forEntity.getBody();
        JSONObject jsonObject = JSONObject.parseObject(body);
        Integer code = jsonObject.getInteger("code");
        if (code == 200){
            String result = jsonObject.getString("data");
            return result.substring(2,result.length()-2);
        }
        return null;
    }

    public static void main(String args[]){
        RestTemplate restTemplate = new RestTemplate();
        TranslateWords translateWords = new TranslateWords();
        translateWords.setContent("我试试效果如何");
        ResponseEntity<String> forEntity = restTemplate.postForEntity(
                "http://47.94.131.193:8000/cntranslateen", translateWords, String.class);
        String body = forEntity.getBody();
        JSONObject jsonObject = JSONObject.parseObject(body);
        Integer code = jsonObject.getInteger("code");
        if (code == 200){
            System.out.println(jsonObject.getString("data"));
            System.out.println(jsonObject.getString("data").substring(2,jsonObject.getString("data").length()-2));
        }
    }
}
